import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const login = (resolve) => {         //登录
  import('components/login/login').then((module) => {
    resolve(module)
  })
}

const register = (resolve) => {      //用户注册
  import('components/register/register').then((module) => {
    resolve(module)
  })
}

const phoneRegister = (resolve) => {  //手机快速注册
  import('components/register/phoneRegister').then((module) => {
    resolve(module)
  })
}

const forgetPwd = (resolve) => {     //找回密码
  import('components/register/forgetPwd').then((module) => {
    resolve(module)
  })
}

const home = (resolve) => {         //内页
  import('components/home').then((module) => {
    resolve(module)
  })
}

const index = (resolve) => {       //首页
  import('components/index/index').then((module) => {
    resolve(module)
  })
}

const btgame = (resolve) => {     //推荐
  import('components/index/btgame').then((module) => {
    resolve(module)
  })
}

const discount = (resolve) => {   //折扣
  import('components/index/discount').then((module) => {
    resolve(module)
  })
}

const danji = (resolve) => {   //单机
  import('components/index/danji').then((module) => {
    resolve(module)
  })
}

const h5game = (resolve) => {     //h5
  import('components/index/h5game').then((module) => {
    resolve(module)
  })
}

const promise = (resolve) => {    //承诺
  import('components/index/promise').then((module) => {
    resolve(module)
  })
}

const H5game = (resolve) => {    //h5游戏
  import('components/index/h5game').then((module) => {
    resolve(module)
  })
}

const server = (resolve) => {    //开服表
  import('components/game/server').then((module) => {
    resolve(module)
  })
}

const gameHall = (resolve) => {   //游戏大厅
  import('components/game/gameHall').then((module) => {
    resolve(module)
  })
}

const rank= (resolve) => {       //排行榜
  import('components/game/rank').then((module) => {
    resolve(module)
  })
}

const earnMoney=(resolve) => {       //赚金
  import('components/game/earnMoney').then((module) => {
    resolve(module)
  })
}

const rebate= (resolve) => {       //返利申请主体
  import('components/rebate/rebate').then((module) => {
    resolve(module)
  })
}

const apply= (resolve) => {       //返利申请
  import('components/rebate/apply').then((module) => {
    resolve(module)
  })
}

const record= (resolve) => {       //返利记录
  import('components/rebate/record').then((module) => {
    resolve(module)
  })
}

const redEnvelope=(resolve)=>{    //抢红包
  import('components/redEnvelope/redEnvelope').then((module) => {
    resolve(module)
  })
}
const redDetail=(resolve)=>{    //红包详情
  import('components/redEnvelope/redDetail').then((module) => {
    resolve(module)
  })
}
const user = (resolve) => {     //个人中心
  import('components/user/user').then((module) => {
    resolve(module)
  })
}
const userMsg = (resolve) => {  //个人信息
  import('components/user/userMsg').then((module) => {
    resolve(module)
  })
}

const bindPhone = (resolve) => {  //绑定手机
  import('components/user/bindPhone').then((module) => {
    resolve(module)
  })
}

const unBindPhone = (resolve) => {       //换绑手机
  import('components/user/unBindPhone').then((module) => {
    resolve(module)
  })
}

const realName = (resolve) => {          //实名认证
  import('components/user/realName').then((module) => {
    resolve(module)
  })
}

const editPassword = (resolve) => {        //修改密码
  import('components/user/editPassword').then((module) => {
    resolve(module)
  })
}

const userCollect = (resolve) => {         //游戏收藏
  import('components/user/userCollect').then((module) => {
    resolve(module)
  })
}

const userFriend = (resolve) => {        //邀请好友
  import('components/user/userFriend').then((module) => {
    resolve(module)
  })
}

const inviteList = (resolve) => {       //邀请列表
  import('components/user/inviteList').then((module) => {
    resolve(module)
  })
}

const userMoney = (resolve) => {      //我的红包
  import('components/user/userMoney').then((module) => {
    resolve(module)
  })
}

const userGift = (resolve) => {         //我的礼包
  import('components/user/userGift').then((module) => {
    resolve(module)
  })
}

const userGirl = (resolve) => {          //美女客服
  import('components/user/userGirl').then((module) => {
    resolve(module)
  })
}
 
const gameDetail = (resolve) => {         //游戏详情
  import('components/gameDetail/gameDetail').then((module) => {
    resolve(module)
  })
}

const publish = (resolve) => {         //发表评论
  import('components/gameDetail/publish').then((module) => {
    resolve(module)
  })
}

const viewAll=(resolve) => {         //查看全部评论
  import('components/gameDetail/viewAll').then((module) => {
    resolve(module)
  })
}

const activity=(resolve) => {          //活动详情
  import('components/gameDetail/activity').then((module) => {
    resolve(module)
  })
}


const newTask=(resolve) => {          //新手任务
  import('components/task/newTask').then((module) => {
    resolve(module)
  })
}

const dailyTask=(resolve) => {          //日常任务
  import('components/task/dailyTask').then((module) => {
    resolve(module)
  })
}

const signTask=(resolve) => {          //签到
  import('components/task/signTask').then((module) => {
    resolve(module)
  })
}

const pointExchange=(resolve) => {          //积分兑换
  import('components/task/pointExchange').then((module) => {
    resolve(module)
  })
}


const lottery=(resolve) => {          //转盘抽奖
  import('components/task/lottery').then((module) => {
    resolve(module)
  })
}

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'home',
      component: home,
      redirect: '/btgame',
      children: [{
          path: '/index',
          name: 'index',
          component: index,
          redirect: '/btgame',
          children: [{
              path: '/btgame',
              name: 'btgame',
              component: btgame,
              meta:{
                keepAlive:true 
             },
            },
            {
              path: '/promise',
              name: 'promise',
              component: promise,
              meta:{
                keepAlive:true 
             },
            },
            {
              path: '/discount',
              name: 'discount',
              component: discount,
              meta:{
                keepAlive:true 
             },
            },
            {
              path: '/danji',
              name: 'danji',
              component: danji,
              meta:{
                keepAlive:true 
             },
            },
            {
              path: '/h5game',
              name: 'h5game',
              component: H5game
            },
          ]

        },
        {
          path: '/user',
          name: 'user',
          component: user,
          meta:{
            keepAlive:false 
          },
        },
        {
            path:'/userMsg',
            name:'userMsg',
            meta: {
                requireAuth: true, 
            },
            component:userMsg,
            children:[
              {
                path:'/bindPhone',
                name:'bindPhone',
                meta: {
                    requireAuth: true, 
                },
                component:bindPhone,
              },
              {
                path:'/unBindPhone',
                name:'unBindPhone',
                meta: {
                    requireAuth: true, 
                },
                component:unBindPhone,
              },
              {
                path:'/realName',
                name:'realName',
                meta: {
                    requireAuth: true, 
                },
                component:realName,
              },
              {
                path:'/editPassword',
                name:'editPassword',
                meta: {
                    requireAuth: true, 
                },
                component:editPassword,
              }]
          },{
            path:'/userGift',
            name:'userGift',
            meta: {
                requireAuth: true, 
            },
            component:userGift 
          },
          {
            path:'/userCollect',
            name:'userCollect',
            meta: {
                requireAuth: true, 
            },
            component:userCollect 
          },
          {
            path:'/userGirl',
            name:'userGirl',
            component:userGirl 
        },
        {
          path:'/earnMoney',
          name:'earnMoney',
          component:earnMoney,
          meta:{
            requireAuth: true,
            keepAlive:false    
          }
        },
        {
          path:'/userFriend',
          name:'userFriend',
          meta: {
              requireAuth: true, 
          },
          component:userFriend,
        },
        {
          path:'/rebate',
          meta: {
              requireAuth: true, 
          },
          name:rebate,
          component:rebate,
          children:[
          {
            path:'/rebate/apply',
            name:apply,
            component:apply
          },
          {
            path:'/rebate/record',
            name:record,
            component:record
          }
          ]
        },
      ]
    },
    {
      path: '/server/:tab?',
      name: 'server',
      component: server,
      meta:{
        keepAlive:true 
     }
    },
    {
      path: '/gameHall/:id?/:index?',
      name: 'gameHall',
      component: gameHall,
      meta: {
        keepAlive: true,
        isBack:true 
      }
    },
    {
      path:'/rank',
      name:rank,
      component:rank,
      meta:{
        keepAlive:true 
     }
    },
    {
      path: '/login',
      name: 'login',
      component: login,
    },
    {
      path: '/phoneRegister',
      name: 'phoneRegister',
      component: phoneRegister
    },
    {
      path: '/register',
      name: 'register',
      component: register
    },
    {
      path: '/forgetPwd',
      name: 'forgetPwd',
      component: forgetPwd,
    },
    {
      name: 'gameDetail',
      path: '/gameDetail/:id',
      component: gameDetail,
      children:[
        {
          name: 'publish',
          path: '/gameDetail/publish',
          component: publish,
        },
        {
          name:'viewAll',
          path: '/gameDetail/viewAll',
          component: viewAll,
        },
        {
          name: 'activity',
          path: '/gameDetail/:id/activity/:cid',
          component: activity,
        }
      ]
    },
    {
      path:'/redDetail',
      name:'redDetail',
      meta: {
          requireAuth: true, 
      },
      component:redDetail 
    },
    {
      path:'/newTask',
      name:'newTask',
      component:newTask,
      meta:{
        keepAlive:false 
      }
    },
    {
      path:'/dailyTask',
      name:'dailyTask',
      component:dailyTask,
      meta:{
        keepAlive:false 
      },
    },
    {
      path:'/signTask',
      name:'signTask',
      component:signTask,
      meta:{
        keepAlive:false 
      },
    },
    // {
    //   path:'/pointExchange',
    //   name:'pointExchange',
    //   component:pointExchange,
    //   meta:{
    //     keepAlive:false 
    //   },
    // },
    {
      path:'/lottery',
      name:'lottery',
      component:lottery,
      meta:{
        keepAlive:false 
      },
    },
    {
      path:'/redEnvelope',
      name:redEnvelope,
      component:redEnvelope,
      children:[
        {
          path:'/userMoney',
          name:'userMoney',
          meta: {
              requireAuth: true, 
          },
          component:userMoney 
        }
      ]
    },
    {
      path:'/inviteList',
      name:'inviteList',
      meta: {
          requireAuth: true, 
      },
      component:inviteList 
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
})
